import { request } from '@/service/request';
import { DD_SYSTEM } from '@/constants/api-pre';

/** dict type */
export type DictType = Api.Common.CommonRecord<{
  /** name */
  name: string;
  /** type */
  type: string;
  /** remark */
  remark: string;
  /** deleted time */
  deletedTime: string;
}>;

/** 字典类型 search params */
export type DictTypeSearchParams = CommonType.RecordNullable<
  Pick<DictType, 'name' | 'type' | 'status'> & Api.Common.CommonSearchParams
>;

export type DictTypeEditAndCreateParams = CommonType.RecordNullable<
  Pick<DictType, 'name' | 'type' | 'status' | 'remark'>
>;

/** user list */
export type DictTypeList = Api.Common.PaginatingQueryRecord<DictType>;

/** 获取字典类型表单 URL */
export function getFetchDictTypeUrl(id: number) {
  return `${DD_SYSTEM}/dict/types/${id}/form`;
}

/** 获取字典类型列表 */
export function fetchGetDictTypeList(params?: DictTypeSearchParams) {
  return request<DictTypeList>({
    url: `${DD_SYSTEM}/dict/types/page`,
    method: 'get',
    params
  });
}

/**
 * 新增字典类型
 *
 * @param data
 */
export function createDictType(data: DictTypeEditAndCreateParams) {
  return request<boolean>({
    url: `${DD_SYSTEM}/dict/types`,
    method: 'post',
    data
  });
}

/**
 * 修改字典类型
 *
 * @param id
 * @param data
 */
export function updateDictType(id: number, data?: DictTypeEditAndCreateParams) {
  return request<boolean>({
    url: `${DD_SYSTEM}/dict/types/${id}`,
    method: 'put',
    data
  });
}

/**
 * 删除字典类型
 *
 * @param ids
 */
export function deleteDictType(ids: string) {
  return request<boolean>({
    url: `${DD_SYSTEM}/dict/types/${ids}`,
    method: 'delete'
  });
}
